package sample;

import java.awt.Color;
import java.io.IOException;

import robocode.ScannedRobotEvent;
import robocode.TeamRobot;

/**
*
* */
public class RoboPrisioneiro extends TeamRobot {



	public RoboPrisioneiro() {
		initRobot();
		
	}

	private void initRobot(){
		setBodyColor(Color.YELLOW);
		setGunColor(Color.YELLOW);
		setRadarColor(Color.BLUE);
		setBulletColor(Color.green);
		setScanColor(Color.RED);
		
		
		//Send the first position
		MensagemTime m = new MensagemTime(getName(), getX(), getY(),false);
		
		try {
			sendMessage("sample.RoboScanner", m);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void run() {

		while (true) {
			turnRadarRight(360);
		}
	}
	
	
	public void followRobot(ScannedRobotEvent event){
		if(event.getDistance() < 20){
			System.out.println("Estou Livre");
			for (int i = 0; i < 50; i++) {
				turnRight(30);
				turnLeft(30);
			}
		}
	}
	
	public void onScannedRobot(ScannedRobotEvent event) {
		
		if(event.getName().startsWith("sample.RoboJogador")){
			followRobot(event);
			
		}
	}
}
